<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:p="http://primefaces.org/ui"
	xmlns:cc="http://java.sun.com/jsf/composite"
	xmlns:hmrTable="http://java.sun.com/jsf/composite/table"	>

<cc:interface >
	<cc:attribute name="handler"	type="com.hemerasolutions.v2trainer.component.interfaces.list.IntensityZoneListCompInterface" required="true"/>
	<cc:attribute name="editable"	type="java.lang.Boolean" 	default="true" required="true" />
</cc:interface>
	
<cc:implementation>
	<span id="#{cc.clientId}" >
		<script type="text/javascript">
			function customToggler(ui){
				if($(ui).hasClass('ui-expanded')){
					$(ui).removeClass('ui-expanded');	
					$(ui).find(".ui-toggler-status").removeClass("ui-icon-triangle-1-s");
					$(ui).find(".ui-toggler-status").addClass("ui-icon-triangle-1-e");
				}else{
					$(ui).addClass('ui-expanded');	
					$(ui).find(".ui-toggler-status").removeClass("ui-icon-triangle-1-e");
					$(ui).find(".ui-toggler-status").addClass("ui-icon-triangle-1-s");
				}};	
		</script>

		<p:outputLabel value="#{msgs.NoExecutionWasSetForThisExercise}" rendered="#{empty cc.attrs.handler.exercise.executions}" />
		<p:outputPanel id="intensityBox" layout="block" rendered="#{not empty cc.attrs.handler.exercise.executions}"  >

			<p:tabView value="#{cc.attrs.handler.exercise.intensityExecutions}" var="intensityExecution" dynamic="true" style="position:relative"   >
				<p:tab title="#{msgs[intensityExecution.execution.name]}" >
					
					<p:dataTable  value="#{intensityExecution.intensityTables}" var="intensityTable"  styleClass="ui-trainingLevelTable" style="max-width:100%;width:100%;overflow:scroll;overflow-x:auto;overflow-y:visible"   >

				        
				        <p:column style="white-space:nowrap;max-width:100%" styleClass="ui-state-default ui-toggle-column"   >
							<div class="ui-row-toggler" style="width:100%;padding:4px;" 
								onclick="customToggler(this);" 
								onmouseover="$(this).addClass('ui-state-hover');$(this).css('border','none')" 
								onmouseout="$(this).removeClass('ui-state-hover')">
								
								<p:outputLabel  styleClass=" ui-toggler-status ui-icon ui-icon-triangle-1-e" 	style="display:inline-block;"  	/>
								<p:outputLabel  value="#{msgs[intensityTable.levelName]}"  				style="display:inline-block;"	/>
							</div>
				        </p:column>
		
						<p:rowExpansion  >
							<h:form prependId="false" >
								<hmrTable:intensityZoneTable handler="#{cc.attrs.handler.intensityZoneTables[intensityTable.uuid]}" editable="#{cc.attrs.editable}"/>
								<h:panelGrid columns="2" width="100%" style="width:100%">
	
								    <p:outputPanel layout="block" rendered="#{cc.attrs.editable}">
									    <p:commandButton value="#{msgs.CopyFromLevel}" update=":#{cc.clientId}:copyIntensityLevelDialog"  oncomplete="wcopyIntensityLevelDialog_#{cc.id}.show();" rendered="#{cc.attrs.editable}">
											<f:setPropertyActionListener target="#{cc.attrs.handler.selIntensityExecution}"		value="#{intensityExecution}"/>
											<f:setPropertyActionListener target="#{cc.attrs.handler.selIntensityZoneTable}" 	value="#{cc.attrs.handler.intensityZoneTables[intensityTable.uuid]}"/>	
									    </p:commandButton>
										<p:commandButton 	value="#{msgs.ReplicateToOthers}" action="#{cc.attrs.handler.replicateGeneral}"  update="@(.ui-intensityTable)" rendered="#{cc.attrs.editable}" >
											<f:setPropertyActionListener target="#{cc.attrs.handler.selIntensityExecution}"		value="#{intensityExecution}"/>
											<f:setPropertyActionListener target="#{cc.attrs.handler.fromIntensityTable}" 		value="#{intensityTable}"/>	
									    </p:commandButton>
								    </p:outputPanel>
								</h:panelGrid>					
							</h:form>
						</p:rowExpansion>
				    </p:dataTable>    
				</p:tab>
			</p:tabView>
			<p:commandButton	value="#{msgs.CopyIntensityZones}" oncomplete="wcopyIntensityDialog_#{cc.id}.show()" update=":#{cc.clientId}:copyIntensityDialog" rendered="#{cc.attrs.editable}"/> 			
		</p:outputPanel>

		<p:dialog id="copyIntensityLevelDialog" header="#{msgs.CopyIntensityZones}"  modal="true" appendTo="@(body)"  widgetVar="wcopyIntensityLevelDialog_#{cc.id}" > 
			<h:form prependId="false">
				<p:dataTable id="copyIntensityLevelTable"  value="#{cc.attrs.handler.selIntensityExecution.intensityTables}" var="intensityTable" paginator="true"  
					paginatorAlwaysVisible="false"  paginatorPosition="bottom" rows="8" emptyMessage="#{msgs.NoResults}" >   
					<p:columnGroup type="header" >  
						<p:row>
							<p:column	colspan="2" >
								<f:facet name="header">
									<h:outputText value="#{msgs.Name}"/>
								</f:facet>
							</p:column>
						</p:row>	 
					</p:columnGroup>
					<p:column colspan="1" headerText="#{msgs.Name}" rendered="#{intensityTable != cc.attrs.handler.selIntensityZoneTable.intensityTable}"  >
						<h:outputText value="#{msgs[intensityTable.levelName]}" />
					</p:column>
					<p:column colspan="1" styleClass="ui-table-button-row" rendered="#{intensityTable != cc.attrs.handler.selIntensityZoneTable.intensityTable}"  >
						<p:commandButton  title="#{msgs.Copy}" icon="ui-icon-copy" action="#{cc.attrs.handler.copyLevelIntensity}" update="@(.ui-intensityTable)" 
							 oncomplete="wcopyIntensityLevelDialog_#{cc.id}.hide();"  styleClass="ui-table-button">
							<f:setPropertyActionListener target="#{cc.attrs.handler.fromIntensityTable}" value="#{intensityTable}"/> 

						</p:commandButton>
					</p:column>
				</p:dataTable>	
			</h:form>
		</p:dialog>
		
		<p:dialog id="copyIntensityDialog" header="#{msgs.CopyIntensityZones}"  modal="true" appendTo="@(body)"  widgetVar="wcopyIntensityDialog_#{cc.id}" > 
			<h:form prependId="false">
				<p:dataTable id="copyIntensityTable" value="#{cc.attrs.handler.modality.versionableExercises}" var="versionableExercise" paginator="true"  
					paginatorAlwaysVisible="false"  paginatorPosition="bottom" rows="8" emptyMessage="#{msgs.NoResults}" >   
					<p:columnGroup type="header" >  
						<p:row>
							<p:column	colspan="2" >
								<f:facet name="header">
									<h:outputText value="#{msgs.Name}"/>
								</f:facet>
							</p:column>
							<p:column	colspan="1" style="padding:0px;margin:0px;">
								<f:facet name="header">
									<h:outputText value="#{msgs.Description}"/>
								</f:facet>
							</p:column>
						</p:row>	 
					</p:columnGroup>
					<p:column colspan="1" headerText="#{msgs.Name}" rendered="#{exercise != cc.attrs.handler.exercise}"  >
						<h:outputText value="#{versionableExercise.currentVersion.name}" />
					</p:column>
					<p:column colspan="1" styleClass="ui-table-button-row"  rendered="#{exercise != cc.attrs.handler.exercise}" >
						<p:commandButton  title="#{msgs.View}" icon="ui-icon-copy" action="#{cc.attrs.handler.copyZones}" update="@(.ui-intensityTable)" 
							 oncomplete="wcopyIntensityDialog_#{cc.id}.hide();"  styleClass="ui-table-button">
							<f:setPropertyActionListener target="#{cc.attrs.handler.selExercise}" value="#{versionableExercise.currentVersion}"/> 
						</p:commandButton>
					</p:column>
					<p:column headerText="#{msgs.Description}" rendered="#{versionableExercise.currentVersion != cc.attrs.handler.exercise}"  >
						<h:outputText value="#{versionableExercise.currentVersion.description}" />
					</p:column>		
				</p:dataTable>	
			</h:form>
		</p:dialog>
	
	</span>
</cc:implementation>


</html>